Introduce Variable

The Introduce Variable refactoring puts the result of the selected expression into a variable. It declares a new variable with the type of the selected expression and uses the expression as initializer. The original expression is replaced with the usage of the variable.

To apply the Introduce Variable refactoring, select an expression in editor and press Ctrl-Alt-V (Refactoring | Introduce Variable).

Edit the name of the variable

and press Enter.

It's quite convenient to use Ctrl-W (select word) to select the expression for applying the Introduce Variable refactoring. It successively selects expanding blocks of code and you may easily select any expression in the code by placing the caret somewhere inside it and pressing Ctrl-W a few times.